// src/utils/shapeFactory.js
import { SVG } from '@svgdotjs/svg.js'

const shapeFactory = {
  rect(draw) {
    return draw.rect(100, 60).fill('#f06').move(50, 50)
  },
  circle(draw) {
    return draw.circle(80).fill('#0af').move(100, 100)
  },
  line(draw) {
    return draw.line(0, 0, 100, 0).stroke({ width: 2, color: '#333' }).move(150, 150)
  },
  polyline(draw) {
    return draw
      .polyline('0,0 50,50 100,0')
      .fill('none')
      .stroke({ width: 2, color: '#009' })
      .move(200, 200)
  },
  polygon(draw) {
    return draw.polygon('0,0 100,0 50,50').fill('#0c6').move(250, 250)
  },
}

// 注册自定义图形（如从 svg 字符串生成）
function registerShape(type, generatorFn) {
  console.log('registerShape', type, generatorFn)
  shapeFactory[type] = generatorFn
}

function createShape(type, draw) {
  const fn = shapeFactory[type]
  return fn ? fn(draw) : null
}

export { registerShape, createShape }
